<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>/net/nas/exports/srv/www/webapps/Projects/Java/CS222/Seminar_2/AssignmentThree/src/Extends2.java.html</title>
<meta name="Generator" content="Vim/7.1">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body bgcolor="#ffffff" text="#000000"><font face="monospace">
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Extends2.java</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Rewrite the Java program extends2 presented in the Course Documents section </font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;to include a Daughter which is inherited from the Parent class.</font><font color="#0000ff">&nbsp;</font><br>
<font color="#0000ff">&nbsp;* </font><br>
<font color="#0000ff">&nbsp;* Code a Daughter method that automatically increases her size to +1 of the </font><br>
<font color="#0000ff">&nbsp;* current Son size and then decreases the Son size by 2. </font><br>
<font color="#0000ff">&nbsp;* </font><br>
<font color="#0000ff">&nbsp;* Compile and Run the program.</font><br>
<font color="#0000ff">&nbsp;*</font><br>
<font color="#0000ff">&nbsp;* </font><font color="#6a5acd">@author</font><font color="#0000ff">&nbsp;&nbsp;John Thomason</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;&nbsp;&nbsp;Date: Nov 16, 2008</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;Course: CS221 Introduction to Java Programming</font><br>
<font color="#0000ff">&nbsp;* Seminar: 2</font><br>
<font color="#0000ff">&nbsp;*&nbsp;&nbsp;Assign: 3</font><br>
<font color="#0000ff">&nbsp;*/</font><br>
<br>
<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Extends2 Class</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;- Description</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>class</b></font>&nbsp;Extends2 {<br>
<br>
&nbsp;&nbsp;<font color="#0000ff">/**</font><br>
<font color="#0000ff">&nbsp;&nbsp; *</font><font color="#6a5acd">&nbsp;Application Entry Point</font><br>
<font color="#0000ff">&nbsp;&nbsp; </font><font color="#0000ff">* </font><font color="#6a5acd">@param</font><font color="#008b8b">&nbsp;args</font><font color="#0000ff">&nbsp;The command line arguments</font><br>
<font color="#0000ff">&nbsp;&nbsp; */</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>public</b></font>&nbsp;<font color="#2e8b57"><b>static</b></font>&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;main(String[]&nbsp;args)&nbsp;{<br>
&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Son joe = <font color="#a52a2a"><b>new</b></font>&nbsp;Son();<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; joe.bumpsize();&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">// call to the parent method</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(<font color="#ff00ff">&quot; joe Son size is &quot;</font>&nbsp;+ joe.size);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; joe.jumpsize();&nbsp;&nbsp;&nbsp;&nbsp;<font color="#0000ff">// call to the son method</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Parent bill = <font color="#a52a2a"><b>new</b></font>&nbsp;Parent(<font color="#ff00ff">15</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(<font color="#ff00ff">&quot; Parent bill size is &quot;</font>&nbsp;+ bill.size);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bill.bumpsize();<br>
&nbsp;&nbsp;&nbsp;&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Daughter emy = <font color="#a52a2a"><b>new</b></font>&nbsp;Daughter();&nbsp;&nbsp; <font color="#0000ff">//Daughter set to default size</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(<font color="#ff00ff">&quot; Daughter Emy's size is &quot;</font>&nbsp;+ emy.size );<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; emy.dumpsize(joe);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000ff">//Emy takes advantage of joe |-{</font><br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; System.out.println(<font color="#ff00ff">&quot; Brother Joe's size is &quot;</font>&nbsp;+ joe.size);<br>
<br>
&nbsp;&nbsp;}<font color="#0000ff">//End main()</font><br>
<br>
}<font color="#0000ff">//End Extends2 Class</font><br>
<br>
<br>
<font color="#0000ff">/**</font><font color="#6a5acd">****************************************************************************</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Parent Class</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>class</b></font>&nbsp;Parent {<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Child classes can directly access this property</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>protected</b></font>&nbsp;<font color="#2e8b57"><b>int</b></font>&nbsp;size;<br>
<br>
&nbsp;&nbsp;<font color="#0000ff">//Constructors</font><br>
&nbsp;&nbsp;Parent()&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;size = <font color="#ff00ff">7</font>;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <font color="#0000ff">//Default child size</font><br>
&nbsp;&nbsp;}<br>
&nbsp;&nbsp;<font color="#0000ff">//Overloaded Constructor</font><br>
&nbsp;&nbsp;Parent(<font color="#2e8b57"><b>int</b></font>&nbsp;size)&nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.size = size;<br>
&nbsp;&nbsp;}<br>
<br>
&nbsp;&nbsp;<font color="#0000ff">//Increase size by one(1)</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;bumpsize(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;size++;<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println();<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<font color="#ff00ff">&quot;Parent size is &quot;</font>&nbsp;+ size);<br>
&nbsp;&nbsp;}<font color="#0000ff">//end bumpsize()</font><br>
<br>
}<font color="#0000ff">//end Parent</font><br>
<br>
<br>
<font color="#0000ff">/**</font><font color="#6a5acd">****************************************************************************</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Son Class</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>class</b></font>&nbsp;Son <font color="#2e8b57"><b>extends</b></font>&nbsp;Parent {&nbsp;&nbsp; <font color="#0000ff">//Son is a subclass of Parent</font><br>
<br>
&nbsp;&nbsp;<font color="#0000ff">//Increase Son's size by two(2)</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;jumpsize(){<br>
&nbsp;&nbsp;&nbsp;&nbsp;size = ++size + <font color="#ff00ff">1</font>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<font color="#ff00ff">&quot;Son size is now &quot;</font>&nbsp;+ size);<br>
&nbsp;&nbsp;}<font color="#0000ff">//end jumpsize()</font><br>
&nbsp;&nbsp;<br>
}<font color="#0000ff">// end Son</font><br>
<br>
<br>
<font color="#0000ff">/**</font><font color="#6a5acd">****************************************************************************</font><br>
<font color="#0000ff">&nbsp;*</font><font color="#6a5acd">&nbsp;Daughter Class</font><br>
<font color="#6a5acd">&nbsp;</font><font color="#0000ff">*/</font><br>
<font color="#2e8b57"><b>class</b></font>&nbsp;Daughter <font color="#2e8b57"><b>extends</b></font>&nbsp;Parent {<br>
&nbsp;&nbsp;<br>
&nbsp;&nbsp;<font color="#0000ff">//Increase the Daughter size by the Son size plus one(1)</font><br>
&nbsp;&nbsp;<font color="#0000ff">//Decrease Son size by two</font><br>
&nbsp;&nbsp;<font color="#2e8b57"><b>void</b></font>&nbsp;dumpsize(Son brother){<br>
&nbsp;&nbsp;&nbsp;&nbsp;<font color="#2e8b57"><b>this</b></font>.size&nbsp;&nbsp;&nbsp;&nbsp;+= (brother.size + <font color="#ff00ff">1</font>);<br>
&nbsp;&nbsp;&nbsp;&nbsp;brother.size -= <font color="#ff00ff">2</font>;<br>
&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(<font color="#ff00ff">&quot;Daughter size is now &quot;</font>&nbsp;+ size);<br>
&nbsp;&nbsp;}<font color="#0000ff">//end dumpsize()</font><br>
&nbsp;&nbsp;<br>
}<font color="#0000ff">// end Daughter</font><br>
</font></body>
</html>
